
var rocket = document.querySelector(".rocket"),
	scrollTop = 0,
	onoff = true

window.addEventListener("scroll",function(e){
	 scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
	if(scrollTop>=400){
		rocket.style.top = "";
		rocket.classList.add("xianshi");
	}else{
		rocket.classList.remove("xianshi")
	}
})


rocket.addEventListener("click",function(){
		if(onoff){
			onoff = false;
			if(scrollTop>=400){
				rocket.classList.add("active");
				var speed = scrollTop/25;
				var timer = setInterval(function(){
				document.documentElement.scrollTop -= speed;
				if(document.documentElement.scrollTop <= 0){
					rocket.style.top = "-50%";
					clearInterval(timer);
					onoff = true;
				}
			},20)
		}
		
		}
		
	})
rocket.addEventListener("transitionend",function(){
	rocket.classList.remove("active")
})
